package cn.weiron.fun.sample.controller;

import cn.weiron.fun.infrastructure.auth.Authority;
import cn.weiron.fun.infrastructure.dto.PageResult;
import cn.weiron.fun.sample.dto.*;
import cn.weiron.fun.sample.result.SamplePointResult;
import cn.weiron.fun.sample.service.SamplePointService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * (SamplePoint)表控制层
 *
 * @author makejava
 * @since 2022-07-16 10:36:09
 */
@Slf4j
@RestController
@RequestMapping("/samplePoint")
public class SamplePointController {

    public SamplePointController(@Qualifier("samplePointServiceImpl") SamplePointService samplePointService) {
        this.samplePointService = samplePointService;
    }

    /**
     * 服务对象
     */
    private final SamplePointService samplePointService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/query/{id}")
    public SamplePointResult queryById(@PathVariable("id") Integer id) {
        return samplePointService.queryById(id);
    }



    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @Authority.Set(mustLogin = false)
    @GetMapping("/del")
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.samplePointService.deleteById(id));
    }

    /**
     * 手机端生成二维码
     * @param id
     * @return
     */
    @Authority.Set(mustLogin = false)
    @GetMapping("/qrCode")
    public void qrCode(HttpServletResponse response, Integer id) {
          samplePointService.qrCode(response,id);
    }


    /**
     * 批量生成
     * @param
     * @return
     */
    @Authority.Set(mustLogin = false)
    @GetMapping("/qrCodes")
    public void batchGeneration(HttpServletResponse response) {
        samplePointService.batchGeneration(response);
    }

}

